package com.sping_boot3.spirng_boot3.juc.异步回调;

import java.util.concurrent.CompletableFuture;

public class 对计算速度选用 {
    public static void main(String[] args) {
        CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> {
            System.out.println("进入A");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            return "A";
        });
        CompletableFuture<String> future1 = CompletableFuture.supplyAsync(() -> {
            System.out.println("进入b");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            return "B";
        });
        CompletableFuture<String> future2 = future.applyToEither(future1, f -> {
            return f + "快些";
        });
        System.out.println(future2.join());


    }
}
